<?php
/**
 * crpVideo
 *
 * @copyright (c) 2007, Daniele Conca
 * @link http://noc.postnuke.com/projects/crpvideo Support and documentation
 * @author Daniele Conca <jami at cremonapalloza dot org>
 * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
 * @package crpVideo
 */

/**
 * crpVideoUI
 */
class crpVideoUI
{

	function crpVideoUI()
	{
		// none
	}

	/**
	 * Draw modify configuration form
	 *
	 * @param array $item element values
	 * @param int $mainCat module's root category
	 * @param array $modvars module's variables
	 *
	 * @return string html
	 */
	function modifyConfig($modvars=array(), $gdArray=array(), $mainCat=null)
	{
		// Create output object
    $pnRender = pnRender::getInstance('crpVideo', false);

    $pnRender->assign($modvars);
    $pnRender->assign('gd_version', $this->gd_version($gdArray['GD Version']));
    $pnRender->assign('mainCategory', $mainCat);

    // Return the output that has been generated by this function
    return $pnRender->fetch('crpvideo_admin_modifyconfig.htm');
	}

	function gd_version($fullstring=null)
	{
		$cache_gd_version = array();

		if (eregi('bundled \((.+)\)$', $fullstring, $matches)) {
			$cache_gd_version['string'] = $fullstring;  // e.g. "bundled (2.0.15 compatible)"
			$cache_gd_version['value'] = (float) $matches[1];     // e.g. "2.0" (not "bundled (2.0.15 compatible)")
		} else {
			$cache_gd_version['string'] = $fullstring;                       // e.g. "1.6.2 or higher"
			$cache_gd_version['value'] = (float) substr($fullstring, 0, 3); // e.g. "1.6" (not "1.6.2 or higher")
		}

		return $cache_gd_version;
	}

	/**
	 * Draw rss feed
	 *
	 * @param array $data feed values
	 * @param array $list elements
	 *
	 * @return string xml
	 */
	function drawFeed($data=array(), $list=array())
	{
		$pnRender = pnRender::getInstance('crpVideo', false);
		$pnRender->assign('data', $data);
		$pnRender->assign('list', $list);

		return $pnRender->fetch('crpvideo_user_getfeed.htm');
	}

	/**
	 * Draw podcast feed
	 *
	 * @param array $data feed values
	 * @param array $list elements
	 *
	 * @return string xml
	 */
	function drawPodcast($data=array(), $list=array(), $modvars=array())
	{
		$pnRender = pnRender::getInstance('crpVideo', false);
		$pnRender->assign('data', $data);
		$pnRender->assign('list', $list);
		$pnRender->assign($modvars);

		return $pnRender->fetch('feeds/crpvideo_template_podcast.htm');
	}

	/**
	 * draw user events list
	 *
	 * @param array $rows of event's value
	 * @param int $category current category if specified
	 * @param int $mainCat module root category
	 * @param array $modvars module's variables
	 *
	 * @return string html code
	 */
	function uploadersList($rows=array(), $category=null, $mainCat=null, $rootCat=null, $cats=null, $modvars=array(), $active=null)
	{
		// Create output object
		$pnRender = pnRender::getInstance('crpVideo');

		// add Profile define
		pnModLangLoad('Profile');

		// Assign the items to the template
		$pnRender->assign('users', $rows);
		$pnRender->assign('category', $category);
		$pnRender->assign('mainCategory', $mainCat);
		$pnRender->assign('rootCat', $rootCat);
		$pnRender->assign('categories', $cats);
		$pnRender->assign('lang', pnUserGetLang());
		$pnRender->assign($modvars);

		// Assign the information required to create the pager
		$pnRender->assign('pager', array (
			'numitems' => pnModAPIFunc('crpVideo',
			'user',
			'countitems',
			array (
				'category' => $category,
				'active'		=> $active,
				'uploaders'		=> true
			)
		), 'itemsperpage' => $modvars['itemsperpage']));

		// Return the output that has been generated by this function
		return $pnRender->fetch('crpvideo_user_view_uploaders.htm');
	}

	/**
	 * draw user events list
	 *
	 * @param array $rows of event's value
	 * @param int $category current category if specified
	 * @param int $mainCat module root category
	 * @param array $modvars module's variables
	 *
	 * @return string html code
	 */
	function uploadsList($videos=array(), $category=null, $mainCat=null, $rootCat=null, $cats=null, $modvars=array(), $uid=null, $active=null)
	{
		// Create output object
		$pnRender = pnRender::getInstance('crpVideo');

		// add Profile define
		pnModLangLoad('Profile');

		// Assign the items to the template
		$pnRender->assign('videos', $videos);
		$pnRender->assign('category', $category);
		$pnRender->assign('mainCategory', $mainCat);
		$pnRender->assign('rootCat', $rootCat);
		$pnRender->assign('categories', $cats);
		$pnRender->assign('uid', $uid);
		$pnRender->assign('lang', pnUserGetLang());
		$pnRender->assign($modvars);

		// Assign the information required to create the pager
		$pnRender->assign('pager', array (
			'numitems' => pnModAPIFunc('crpVideo',
			'user',
			'countitems',
			array (
				'category' => $category,
				'active'		=> $active,
				'uid'		=> $uid
			)
		), 'itemsperpage' => $modvars['itemsperpage']));

		// Return the output that has been generated by this function
		return $pnRender->fetch('crpvideo_user_view_uploads.htm');
	}

}
?>
